import factory from "./axios"

/** 统一前缀 */
const prefix = "/api"

/** 分页查询参数 */
export interface SearchAppPageListParams {
  page?: number | string
  size?: number | string
  now_name?: string
  app_name?: string
}

/** 按 ID 查询参数 */
export interface SearchAppGetByIdParams {
  id: number | string
}

/** 删除参数 */
export interface SearchAppDeleteParams {
  id: number | string
}

/** 频道列表查询参数 */
export interface SearchAppChannelListParams {
  ids?: string
  ids_array?: Array<number | string>
  keyword?: string
  app_id?: string | number
}

/** 列表页返回项 */
export interface SearchAppListItem {
  id: number | string
  app_name: string
  node_name: string
  app_status?: "active" | "down" | string
  unit_name?: string
  create_time?: string
  index_db_list?: string[] | string
  [k: string]: any
}

/** 频道列表返回项 */
export interface SearchAppChannelListItem {
  id?: string | number
  channel_id?: string | number
  app_channel_id?: string | number
  channel_name?: string
  channel_show_name?: string
  search_interface?: string
  interface_type?: string
  entry_style?: string
  create_time?: string
  app_id?: string | number
  [k: string]: any
}

/** 新增/修改通用的频道项 */
export interface SearchAppChannelItem {
  channel_name: string
  channel_show: "true" | "false" | boolean
  channel_show_name: string
  channel_sort: number
  app_id: string
  channel_id?: string
}

/** 新增 */
export interface SearchAppAddPayload {
  app_name: string
  node_name: string
  app_icon?: string
  app_status: string
  unit_name: string
  channel_list: SearchAppChannelItem[]
}

/** 修改 */
export interface SearchAppUpdatePayload {
  id?: number | string
  app_id?: number | string
  app_name?: string
  node_name?: string
  app_icon?: string
  app_status?: string
  unit_name?: string
  channel_list?: SearchAppChannelItem[]
  [k: string]: any
}

/** ===== 上传图片 ===== */
export interface SearchAppUploadImageParams {
  /** 表单字段名为 file */
  file: File | Blob
}
export interface SearchAppUploadImageResp {
  url?: string
  filename?: string
  [k: string]: any
}
/** =================================================== */

const api = factory({
  get: {
    /** 分页查询列表 */
    searchAppPageList: `${prefix}/data_service/search_app/page_list`,

    /** 查询单条记录 */
    searchAppGetById: `${prefix}/data_service/search_app/get_by_id/:id`,

    /** 查询频道列表 */
    searchAppChannelList: `${prefix}/data_service/search_app/channel_list`,

    /** 删除 */
    searchAppDelete: `${prefix}/data_service/search_app/delete/:id`,
  },
  post: {
    /** 新增搜索应用 */
    searchAppAdd: `${prefix}/data_service/search_app/add`,
    /** 修改搜索应用 */
    searchAppUpdate: `${prefix}/data_service/search_app/update`,
    /** 上传图片 */
    searchAppUploadImage: `${prefix}/data_service/search_app/upload_image/`,
  },
  file: {
    /** 上传图片 */
    searchAppUploadImage: `${prefix}/data_service/search_app/upload_image/`,
  },
})

export default api
